#include "hwnd_delegate.h"

WindowDelegate::WindowDelegate()
    : m_hWnd( 0 )
{

}

void WindowDelegate::Attatch( HWND hWnd )
{
    m_hWnd = hWnd;
}

HWND WindowDelegate::Detatch()
{
    HWND hWnd = m_hWnd;
    m_hWnd = 0;
    return hWnd;
}

bool WindowDelegate::Drag()
{
    if( m_hWnd )
    {
        ::SendMessage( m_hWnd, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0 );
        return true;
    }

    return false;
}

bool WindowDelegate::Update( const core::rect & rect )
{
    if( m_hWnd )
    {
        RECT rcUpdate = { rect.left, rect.top, rect.right, rect.bottom };
        ::InvalidateRect( m_hWnd, &rcUpdate, FALSE );
    }
    return false;
}